
package com.android.formula.task;

import java.util.ArrayList;

import android.content.Context;

import com.android.formula.common.MyApplication;
import com.android.formula.dao.SubjectDao;
import com.android.formula.database.SQLiteTable;
import com.android.formula.model.Language;
import com.android.formula.model.Subject;
import com.android.formula.utils.Constants;

/**
 * Get a Spot by Id
 */
public class GetSubjectDBTask extends BaseDatabaseTask<Language, ArrayList<Subject>> {

    public GetSubjectDBTask(Context context, Language param,
            IDataEventHandler<ArrayList<Subject>> dataEventHandler) {
        super(context, param, null, dataEventHandler);
    }

    @Override
    protected ArrayList<Subject> execute() {
        SQLiteTable sqlt = MyApplication.getSqLiteTable();
        if (sqlt == null || mRequestParams == null) {
            return null;
        }

        sqlt.open();
        SubjectDao dao = new SubjectDao(Subject.class, mContext, sqlt.getDatabase());
        ArrayList<Subject> list = dao.getItemsFromId(Constants.TABLE_SUBJECT_COL_LANGUAGEID,
                "" + mRequestParams.getId());
        sqlt.close();
        if (!list.isEmpty()) {
            return list;
        } else {
            return null;
        }
    }
}
